package com.qiyou.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qiyou.dao.IActivityInvitationDao;
import com.qiyou.dao.factory.DaoFactory;
import com.qiyou.entity.ActivityInvitation;

/**
 * 邀请业务逻辑处理
 * @author 赛艳志
 */
@WebServlet(name = "ActivityInvitation", urlPatterns = { "/ActivityInvitation" })
public class ActivityInvitationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		String userID = request.getParameter("userId");
		String sacId = request.getParameter("acId");
		
		try {
			long iacId = -1;
			iacId = Long.parseLong(sacId);
			
			if ((iacId > 0) && (null != userID)) {
				IActivityInvitationDao invitationDao = DaoFactory.getIActivityInvitationDao();
				
				ActivityInvitation activityInvitation = new ActivityInvitation();
				activityInvitation.setAcID(iacId);
				activityInvitation.setAiState("R");
				activityInvitation.setUserID(userID);
				
				boolean falg = invitationDao.doCreate(activityInvitation );
				
				if (falg) {
					request.getRequestDispatcher("index.jsp").forward(request, response);
				}else {
					response.getWriter().print("<script type='text/javascript'>alert('加入活动时出错！');history.go(-1);</script>");
				}
			}
		} catch (Exception e) {
			response.getWriter().print("<script type='text/javascript'>alert('请求的信息有误！');history.go(-1);</script>");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
